<?php
namespace App\Services;

use App\Models\Hospital;
use App\Traits\PageTrait;

class HospitalService
{
    use PageTrait;
    /**
     * 获取医院列表
     * @param array $condition 条件
     * @param string $sort 排序
     */ 
    public function getList($condition, $sort = 'id desc')
    {
    
        $query = Hospital::query();
        //搜索
        if(isset($condition['name'])) {
            $query->where('name', 'like', '%'.$condition['name'].'%');
        }
        $query->where('status', 0);
        //排序
        $query->orderBy($sort);
        self::JsonPage($query);
    }
    /**
     * 获取推荐医院
     */
    public function getRecommend($limit)
    {
        return Hospital::query()->where('status', 0)->select('id', 'name', 'logo')->where('is_recommend', 1)->limit($limit)->orderBy('sort', 'desc')->get();
    }
    public function getDetail($id)
    {
        return Hospital::query()->where('id', $id)->firstOrFail();
    }
}